import { makeAutoObservable } from 'mobx';
import * as api from './api';

export default class DashboardStore {
  /* 查询参数
   */
  query = {};

  _member_menu = {
    0: '9',
    1: '0',
    2: '1',
    3: '2',
    4: '-1',
  };

  constructor(rootStore) {
    this.rootStore = rootStore;
    makeAutoObservable(this, { rootStore: false });
  }

  get api() {
    return api;
  }

  /**
   * 初始化包车订单搜索条件
   */
  resetQuery() {
    this.queryCC = { ...this.query };
    this.queryST = { ...this.query };
    this.queryBUS = { ...this.query };
    this.queryCT = { ...this.query };
  }

  * get() {
    this.pipeData = yield api.getPipe();
  }

  * search(args) {
    return yield api.search(args);
  }

  * orderCount(args) {
    return yield api.orderCount(args);
  }

  * orderTotal(args) {
    return yield api.orderTotal(args);
  }

  * pointTrade(args) {
    return yield api.pointTrade(args);
  }

  * orderGraph(args) {
    return yield api.orderGraph(args);
  }

  * memberCount(args) {
    const res = yield Promise.all([
      api.memberCount({ status: [0, 1, 2], ...args }),
      api.memberCount({ status: [0], ...args }),
      api.memberCount({ status: [1], ...args }),
      api.memberCount({ status: [2], ...args }),
      api.memberCount({ status: [-1], ...args }),
    ]);
    return res;
  }

  * fetch(args) {
    return yield api.getOrderBar({ ...args });
  }
}
